package com.googlecode.jerato.library.store;

import java.util.List;
import java.util.Map;

import com.googlecode.jerato.core.FunctionParameters;
import com.googlecode.jerato.core.store.StoreParameters;
import com.googlecode.jerato.library.StringHashMap;

public class StoreParametersImpl extends StringHashMap implements StoreParameters{
	protected static final long serialVersionUID = StoreParametersImpl.class.hashCode();
	protected FunctionParameters _parent;

	public StoreParametersImpl(){
		
	}

	public StoreParametersImpl(FunctionParameters input){
		putAll(input);
	}

	public FunctionParameters getParent(){
		return _parent;
	}

	public boolean existsParent(){
		return _parent != null;
	}

	public void flushParent(){
		if(_parent != null){
			_parent.clear();
			_parent.putAll(this);
			if(_parent instanceof StoreParameters){
				((StoreParameters)_parent).flushParent();
			}
		}
	}

	public void setResultList(List list){
		put(XmlStoreFunction.KEY_RESULT_LIST, list);
	}

	public List getResultList(){
		return (List)get(XmlStoreFunction.KEY_RESULT_LIST);
	}

	public boolean isResultExists(){
		Boolean result = (Boolean)get(XmlStoreFunction.KEY_RESULT_EXISTS);
		if(result == null || !result.booleanValue()){
			return false;
		}
		return true;
	}

	public Map getResultFirst(){
		Map result = (Map)get(XmlStoreFunction.KEY_RESULT_FIRST);
		return result;
	}

	public int getResultCount(){
		Integer result = (Integer)get(XmlStoreFunction.KEY_RESULT_COUNT);
		return result.intValue();
	}
	
	public int getUpdateCount(){
		Integer result = (Integer)get(XmlStoreFunction.KEY_UPDATE_COUNT);
		return result.intValue();
	}
}
